﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using INSTA.StockApplication.BLL;

namespace INSTA.StockApplication.UI.Windows
{
    public partial class Produit : Form
    {
        DataGridViewButtonColumn btnUpdate = new DataGridViewButtonColumn();
        DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
        public Produit()
        {
            InitializeComponent();
            RefreshDataSource();
            AddDataGridViewButtons();
            FillComboBox(comboMarque,1);
            FillComboBox(comboCategorie, 2);
            FillComboBox(comboFournisseur, 3);
        }

        private void RefreshDataSource()
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = Products.GetListOfProductsFromDatabase();
            dataGridView1.DataSource = bs;
            bs.ResetBindings(false);
        }

        private void AddDataGridViewButtons()
        {
            btnUpdate.UseColumnTextForButtonValue = true;
            btnDelete.UseColumnTextForButtonValue = true;
            btnUpdate.Name = "Approvisioner";
            btnDelete.Name = "Supprimer";
            btnUpdate.Text = "Approvisioner";
            btnDelete.Text = "Supprimer";
            dataGridView1.Columns.Add(btnUpdate);
            dataGridView1.Columns.Add(btnDelete);
        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Brands.GetListProductsByMarqueFromDatabase(Convert.ToInt32(comboMarque.SelectedIndex.ToString()));
        }

        private void FillComboBox(ComboBox combo,int num)
        {
            switch (num)
            {
                case 1 :   
                    combo.DataSource = Brands.GetListMarqueFromDatabase();
                    combo.ValueMember = "ID_MARQUE";
                    combo.DisplayMember = "NOM_MARQUE";
                    break;
                case 2 :
                    combo.DataSource = Category.GetListCategorieFromDatabase();
                    combo.ValueMember = "ID_CATEGORIE";
                    combo.DisplayMember = "LIBELLE_CATEGORIE";
                    break;
                case 3 :
                    combo.DataSource = Provider.GetListFournisseurFromDatabase();
                    combo.ValueMember = "ID_FOURNISSEUR";
                    combo.DisplayMember = "NOM_FOURNISSEUR";
                    break;
            }
            {
                
            }
        }

        private void comboMarque_SelectedIndexChanged(object sender, EventArgs e)
        {
            //dataGridView1.DataSource = Brands.GetListProductsByMarqueFromDatabase(Convert.ToInt32(comboMarque.ValueMember));
        }
    }
}
